import { createStore } from 'vuex';

export default createStore({
  state: {
    user: null,
    isAuthenticated: false
  },
  mutations: {
    setUser(state, user) {
      console.log('设置用户数据:', user); // 添加调试信息
      state.user = user;
      console.log('设置后的用户数据:', state.user); // 添加调试信息
    },
    setIsAuthenticated(state, status) {
      state.isAuthenticated = status;
    }
  },
  getters: {
    isLoggedIn: state => state.isAuthenticated,
    user: state => state.user
  },
  actions: {
    logout({ commit }) {
      commit('setUser', null);
      commit('setIsAuthenticated', false);
    }
  }
});